package config

import (
	"gitee.com/dh114007/wechat_token/driver"
	"gopkg.in/yaml.v2"
	"io/ioutil"
	"log"
)

type BaseOptions struct {
	Bind string `yaml:"bind"`
	Node int64  `yaml:"node"`
}

type WechatOptions struct {
	Store string            `yaml:"store"`
	Keys  map[string]string `yaml:"keys"`
}

type AuthOptions struct {
	Keys map[string]string `yaml:"keys"`
}

type Config struct {
	Base   *BaseOptions          `yaml:"base"`
	Logger *driver.LoggerOptions `yaml:"logger"`
	Wechat *WechatOptions        `yaml:"wechat"`
	Auth   *AuthOptions          `yaml:"auth"`
}

var Conf *Config

func NewConfigWithYaml(filePath string) *Config {
	Conf = &Config{}
	yamlFile, err := ioutil.ReadFile(filePath)
	if err != nil {
		log.Printf("yamlFile.Get err #%v ", err)
	}
	err = yaml.Unmarshal(yamlFile, Conf)
	if err != nil {
		log.Fatalf("Unmarshal: %v", err)
	}
	return Conf
}
